#ifndef __ALARM_H__
#define __ALARM_H__

#include "typedef.h"

enum DC_ALARM_CODE{
    //pgn8704
    DC_ALARM_BUTTON=0 ,//"急停按钮故障"
    DC_ALARM_SMOKE, //"烟感故障"
    DC_ALARM_AC_CIRCUIT_BREAKER, //"交流输入断路器故障"
    DC_ALARM_DC_BUS_CONTACT, //"直流母线输出接触器拒动/误动故障"

    DC_ALARM_DC_BUS_FUSE, //"直流母线输出熔断器故障"
    DC_ALARM_GUN_ELEC_LOCK, //"充电接口电子锁故障"
    DC_ALARM_DEV_FAN, //"充电桩风扇故障"
    DC_ALARM_ARRESTER, //"避雷器故障"

    DC_ALAEM_ISOLATION_CHECK, //"绝缘监测故障"
    DC_ALARM_BATTERY_REVERSE, //"电池极性反接故障"
    DC_ALARM_CHARGING_VCG, //"充电中车辆控制导引故障"
    DC_ALARM_DEV_OVER_TEMP, //"充电桩过温故障"

    DC_ALARM_GUN_OVER_TEMP, //"充电接口过温故障"
    DC_ALARM_GUN_NOT_HOMING, //"充电枪未归位告警"
    DC_ALARM_BMS_COMMUNICATE , //"BMS通信故障"
    DC_ALARM_VOL_IN_OVER, //"输出电压过压故障"

    DC_ALARM_VOL_IN_LOW, //"输入电压欠压故障"
    DC_ALARM_DC_BUS_VOL_OVER, //"直流母线输出过压故障"
    DC_ALARM_DC_BUS_VOL_LOW, //"直流母线输出欠压故障"
    DC_ALARM_DC_BUS_CURRT_OVER, //"直流母线输出过流故障"

    DC_ALARM_MOD_FAIL, //"充电模块故障"
    DC_ALARM_MOD_AC_FAIL, //"充电模块交流输入故障"
    DC_ALARM_MOD_AC_VOL_OVER, //"充电模块交流输入过压故障"
    DC_ALARM_MOD_AC_VOL_LOW, //"充电模块交流输入欠压故障"

    DC_ALARM_MOD_AC_LOST_PHASE, //"充电模块交流输入缺相故障"
    DC_ALARM_MOD_DC_SHORT, //"充电模块直流输出短路故障"
    DC_ALARM_MOD_DC_CURRT_OVER, //"充电模块直流输出过流故障"


    DC_ALARM_MOD_DC_VOL_OVER, //"充电模块直流输出过压故障"
    DC_ALARM_MOD_DC_VOL_LOW, //"充电模块直流输出欠压故障"
    DC_ALARM_MOD_TEMP_OVER, //"充电模块过温故障"
    DC_ALARM_MOD_COMM_FAIL, //"充电模块通信故障"
    DC_ALARM_MOD_FAN_FAIL, //"充电模块风扇故障"

    //pgn8960
    DC_ALARM_DEV_DOOR_FAIL, //"门禁故障"
    DC_ALARM_DC_CONTACT_ADHESION, //"直流输出接触器粘连故障"
    DC_ALAEM_ISOLATION_CHECK0X23, //"绝缘检测告警"

    DC_ALARM_RELEASE, //"泄放回路故障"
    DC_ALARM_OVER_TEMP0X23, //"充电桩过温告警"
    DC_ALARM_GUN_OVER_TEMP0X23, //"充电枪过温告警"
    DC_ALARM_AC_CONTACOR0X23, //"交流输入接触器据动/误动故障"

    DC_ALARM_AC_CONTACT_ADHESION0X23, //"交流输入接触器粘连故障"
    DC_ALARM_AUX_POWER0X23, //"辅助电源故障"
    DC_ALARM_SHUNT_CONTACT0X23, //"并联接触器据动/误动故障"
    DC_ALARM_SHUNT_CONTACT_ADHESION0X23, //"并联接触器粘连故障" 

    DC_ALARM_OTHER, //其他类型故障

    DC_ALARM_ELEC_METER, //电表通信故障
    
    DC_ALARM_MAX
};

#define ALARM_OCCURED 0
#define ALARM_RECOVERED 1

typedef void (*alarm_notify)(int32_t gunid, const char_t *alarmcode, char_t state);

int32_t alarm_is_fault(int32_t gunid);
int32_t alarm_is_alarm(int32_t gunid);
int32_t alarm_is_emeter_alarm(int32_t gunid);
int32_t alarm_update_total_fault(int32_t gunid, uint8_t state);
int32_t alarm_update_total_alarm(int32_t gunid, uint8_t state);
void alarm_get_alarmcode(int32_t gunid, char_t *code);
void alarm_get_alarm_desc(int32_t gunid, char_t *code);
void alarm_set_other_alarm_code(int32_t gunid, uint16_t code);
int32_t alarm_deal(int32_t gunid, enum DC_ALARM_CODE code, uint8_t state);
void alarm_all_up(void);
int32_t alarm_init(alarm_notify callback);  

#endif

